home *** CD-ROM | disk | FTP | other *** search
/ Hornet Underground 2 / Hornet Underground Volume 2.iso / demos / 1995 / p / posintro.arj / POSINTRO.C < prev    next >
C/C++ Source or Header  |  1995-07-23  |  10KB  |  455 lines

  1.  
  2. #include <i86.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <conio.h>
  7. #include <math.h>
  8.  
  9. // -----------------------
  10.  
  11. void VGA_WaitForRetrace(void) {
  12.     while ((inp(0x3DA) & 8) == 0);
  13. }
  14.  
  15. void VGA_WaitForDisplay(void) {
  16.     while ((inp(0x3DA) & 8) == 8);
  17. }
  18.  
  19. void VGA_VSync(void) {
  20.     VGA_WaitForDisplay();
  21.     VGA_WaitForRetrace();
  22. }
  23.  
  24. // -----------------------
  25.                   
  26. void PAL_Fade(char *inicial, char *final)
  27. {
  28. int n,distintos;
  29. char *dest,*tmp;
  30. char temppal[768];
  31. memcpy(temppal,inicial,768);
  32. distintos=1;
  33. while(distintos && !kbhit()){
  34.         distintos=0;
  35.         dest=final; 
  36.         tmp=temppal;
  37.         for(n=0;n<768;n++){
  38.             if(*tmp!=*dest){
  39.                 distintos=1;
  40.                 if(*tmp<*dest)
  41.                         (*tmp)++;
  42.                 else    
  43.                         (*tmp)--;
  44.             }
  45.             tmp++;
  46.             dest++;
  47.         }
  48.         VGA_VSync();
  49.         PAL_SetPal(temppal);
  50.     }
  51. }
  52.  
  53. void VuelcaPal(char *pal, int n);
  54. #pragma aux VuelcaPal parm [ESI] [ECX] modify [EDX] = \
  55.     "MOV EDX,0x3C9" \
  56.     "lp:"           \
  57.     "OUTSB"         \
  58.     "OUTSB"         \
  59.     "OUTSB"         \
  60.     "SUB    ECX,3"  \
  61.     "JA lp"
  62.  
  63. void PAL_SetPal(char *paleta)
  64. {
  65.     if (paleta == NULL) return;    
  66.  
  67.     outp(0x3c8, 0x0); // Set to first color
  68.     VuelcaPal(paleta, 768);
  69. /*
  70.     for (i= 0; i<768; i++)
  71.     {
  72.  
  73.         outp(0x3c9, paleta[i]); };
  74. */
  75. }
  76.  
  77. // -----------------------
  78.  
  79. #pragma aux memcpy parm [EDI] [ESI] [ECX] = \
  80.     "MOV    EAX,ECX" \
  81.     "SHR    ECX,2"   \
  82.     "REP MOVSD"      \
  83.     "AND    EAX,3"   \
  84.     "MOV    ECX,EAX" \
  85.     "REP MOVSB"
  86.  
  87.  
  88. typedef unsigned char  bool;
  89. typedef unsigned char  byte;
  90. typedef unsigned short word;
  91. typedef unsigned long  dword;
  92.  
  93. typedef signed char  sbyte;
  94. typedef signed short sword;
  95. typedef signed long  sdword;
  96.  
  97. #define PUBLIC  extern
  98. #define PRIVATE static
  99.  
  100. enum {
  101.     FALSE,
  102.     TRUE
  103. };
  104.  
  105. union REGS regs;
  106. struct SREGS sregs;
  107.  
  108. typedef byte TScr[200][320];
  109. typedef byte (*PScr)[320];
  110. TScr scr;
  111. #define vgascr ((PScr)0xA0000UL)
  112.  
  113. struct {
  114.     byte head[32];
  115.     byte pal[768];
  116.     TScr scr;
  117. } cel;
  118.  
  119. void DumpScr(void) {
  120.     static int cont;
  121.     int i, j;
  122.     byte *p = vgascr;
  123.     byte *s;
  124.     int w1, w2;
  125.  
  126.     p += 320 *(cont&1)+ ((cont & 2)>>1);
  127.     w1 = 321 - (cont&2);
  128.     w2 = 319 + (cont&2);
  129.  
  130.     cont++;
  131.  
  132.     for(i=0;i<100;i+=2){
  133.         s=scr[i];
  134.         for(j=0;j<160;j++){
  135.                 *p++=*s;
  136.                 s++;
  137.                 p++;
  138.                 }
  139.         p+=w1;
  140.         s=scr[i+1];
  141.         for(j=0;j<160;j++){
  142.                 *p++=*s;
  143.                 s++;
  144.                 p++;
  145.                 }
  146.         p+=w2;
  147.         }
  148.  
  149. }
  150.  
  151. #define LONGX 160
  152. #define LONGY 100
  153.  
  154. char pal1[768], pal2[1152], pal3[768];
  155. int CambPal = 0;
  156.  
  157. int CosTab[2048];
  158.  
  159.  
  160. dword tdist1[2*LONGY+1][2*LONGX+1];
  161. dword tdist2[2*LONGY+1][2*LONGX+1];
  162. dword tdist3[2*LONGY+1][2*LONGX+1];
  163. dword tdist4[2*LONGY+1][2*LONGX+1];
  164. dword tdist5[2*LONGY+1][2*LONGX+1];
  165.  
  166. typedef struct {
  167.     int x, y, px, py, vx, vy;
  168. } TCenter;
  169.  
  170. TCenter
  171.     g1 = {65, 55}
  172.    ,g2 = {75, 135}
  173.    ,g3 = {145, 60}
  174. //    g1 = {130, 10}
  175. //   ,g2 = {150, 70}
  176. //   ,g3 = {50, 90}
  177. ;
  178.  
  179. #define wt1 31 //123
  180. #define wt2 13 //35
  181. #define wt3 7  //67
  182.  
  183. #define beta1 5
  184. #define beta2 25
  185. #define beta3 15
  186.  
  187. void InitCenter(TCenter  *c) {
  188.     c->px = (c->px * LONGX) / 100;
  189.     c->py = (c->py * LONGY) / 100;
  190.     c->px = c->x << 8;
  191.     c->py = c->y << 8;
  192.     c->vx = 0;
  193.     c->vy = 0;
  194. }
  195.  
  196. #define VEL 16
  197.  
  198. void MoveCenter(TCenter  *c) {
  199.     if (c->py < (LONGY << 8))
  200.         c->vy += VEL;
  201.     else if (c->py > (LONGY << 8))
  202.         c->vy -= VEL;
  203.     if (c->px < (LONGX << 8))
  204.         c->vx += VEL;
  205.     else if (c->px > (LONGX << 8))
  206.         c->vx -= VEL;
  207.     c->px += c->vx;
  208.     c->py += c->vy;
  209.     c->x = c->px >> 8;
  210.     c->y = c->py >> 8;
  211. }
  212.  
  213. void main() {
  214.     int i, j;
  215.     char *p;
  216.     byte *s;
  217.  
  218.     int time;
  219.  
  220.     int *ct1, *ct2, *ct3;
  221.     int fase1 = 134, fase2 = 345, fase3 = 234;
  222.  
  223.     printf("If you don't own a 486 with coprocessor you better not\n"
  224.            "run this. Look at the code to find out why...\n"
  225.            );
  226.  
  227.     {
  228.         FILE *f;
  229.         f = fopen("poslogo.cel", "rb");
  230.         fread(&cel, 64800, 1, f);
  231.         fclose(f);
  232.     }
  233.  
  234.     for (i=0; i< 2048; i++)
  235.     {   CosTab[i] = 256.0*cos(i*3.149648/512.0);
  236.     }
  237.  
  238.     for (i = 0; i < 2*LONGY+1; i++)
  239.         for (j = 0; j < 2*LONGX+1; j++)
  240.         {    tdist1[i][j] = (beta1 *(int) sqrt((j-LONGX)*(j-LONGX) +
  241.             (i-LONGY)*(i-LONGY))) %  1024;
  242.            tdist2[i][j] = (beta2*(int) sqrt((j-LONGX)*(j-LONGX) +
  243.             (i-LONGY)*(i-LONGY))) %  1024;
  244.             tdist3[i][j] = (beta3 *(int) sqrt((j-LONGX)*(j-LONGX) +
  245.             (i-LONGY)*(i-LONGY))) %  1024;
  246.         }
  247.     for (i = 0; i < 2*LONGY+1; i++)
  248.         for (j = 0; j < 2*LONGX+1; j++)
  249.             tdist4[i][j] = 1024/(1+sqrt((j-LONGX)*(j-LONGX) + (i-LONGY)*(i-LONGY)));
  250.  
  251.     for (i = 0; i < 2*LONGY+1; i++)
  252.         for (j = 0; j < 2*LONGX+1; j++)
  253.             tdist5[i][j] = (int) sqrt((j-LONGX)*(j-LONGX) + (i-LONGY)*(i-LONGY)) %
  254.             1024;
  255.     memset(pal3, 0, 768);
  256.  
  257.     p = pal1;
  258.     for (i = 0; i < 64; i++) {
  259.         *p++ = 0;
  260.         *p++ = i;
  261.         *p++ = i;
  262.     }
  263.     for (i = 0; i < 64; i++) {
  264.         *p++ = i;
  265.         *p++ = 63-i;
  266.         *p++ = 63;
  267.     }
  268.     for (i = 0; i < 64; i++) {
  269.         *p++ = 63;
  270.         *p++ = i;
  271.         *p++ = 63-i;
  272.     }
  273.     for (i = 0; i < 64; i++) {
  274.         *p++ = 63-i;
  275.         *p++ = 63-i;
  276.         *p++ = 0;
  277.     }
  278.  
  279.     p = pal2;
  280.     for (i = 0; i < 64; i++) {
  281.         *p++ = i;
  282.         *p++ = 0;
  283.         *p++ = 0;
  284.     }
  285.     for (i = 0; i < 64; i++) {
  286.         *p++ = 63-i;
  287.         *p++ = 0;
  288.         *p++ = 0;
  289.     }
  290.     for (i = 0; i < 64; i++) {
  291.         *p++ = 0;
  292.         *p++ = 0;
  293.         *p++ = i;
  294.     }
  295.     for (i = 0; i < 64; i++) {
  296.         *p++ = 0;
  297.         *p++ = 0;
  298.         *p++ = 63-i;
  299.     }
  300.     for (i = 0; i < 64; i++) {
  301.         *p++ = 0;
  302.         *p++ = i;
  303.         *p++ = 0;
  304.     }
  305.     for (i = 0; i < 64; i++) {
  306.         *p++ = 0;
  307.         *p++ = 63-i;
  308.         *p++ = 0;
  309.     }
  310.  
  311.  
  312.     InitCenter(&g1);
  313.     InitCenter(&g2);
  314.     InitCenter(&g3);
  315.  
  316.     regs.w.ax = 0x13;
  317.     int386(0x10, ®s, ®s);
  318.  
  319. otra:
  320.  
  321.     VGA_VSync();
  322.     PAL_SetPal(pal3);
  323.  
  324. //    outp(0x3D4, 9);
  325. //  outp(0x3D5, (inp(0x3D5) & 0xE0) + 1);
  326.  
  327.     memcpy(vgascr, cel.scr, 64000);
  328.  
  329.     VGA_VSync();
  330.     PAL_Fade(pal3,cel.pal);
  331.  
  332.     for (time = 0; time < 70*5 && !kbhit(); time++) VGA_VSync();
  333. //    getch();
  334.  
  335.  
  336.     PAL_SetPal(pal1);
  337.  
  338.   //  outp(0x3D4, 9);
  339.     //outp(0x3D5, (inp(0x3D5) & 0xE0) + 3);
  340.  
  341.     memset(vgascr, 0, 64000);
  342.     time = 0;
  343.     while (time < 20*10 && !kbhit()) {
  344.         for (i = LONGY/2; i < LONGY+LONGY/2; i++) {
  345.             s = scr[i-LONGY/2];
  346.             for (j = LONGX/2; j < LONGX+LONGX/2; j++)
  347.                 *s++ = (
  348.                             tdist4[LONGY+i-g1.y][LONGX+j-g1.x]
  349.                            -tdist4[LONGY+i-g2.y][LONGX+j-g2.x]
  350.                            +tdist4[LONGY+i-g3.y][LONGX+j-g3.x]
  351.                            ) / 2;
  352.         }
  353.         time++;
  354.         VGA_VSync();
  355.         DumpScr();
  356.  
  357.         MoveCenter(&g1);
  358.         MoveCenter(&g2);
  359.         MoveCenter(&g3);
  360.     }
  361. //    getch();
  362.     
  363.     fase1 = 134, fase2 = 345, fase3 = 234;
  364.  
  365.     ct1 = CosTab + (fase1 += wt1) % 1024;
  366.     ct2 = CosTab + (fase2 += wt2) % 1024;
  367.     ct3 = CosTab + (fase3 += wt3) % 1024;
  368.     time = 0;
  369.     while (time < 20*10 && !kbhit()) {
  370.  
  371. /*
  372.         ct1 = CosTab + (fase1 += wt1) % 1024;
  373.         ct2 = CosTab + (fase2 += wt2) % 1024;
  374.         ct3 = CosTab + (fase3 += wt3) % 1024;
  375. */
  376.         for (i = LONGY/2; i < LONGY+LONGY/2; i++) {
  377.             s = scr[i-LONGY/2];
  378.             for (j = LONGX/2; j < LONGX+LONGX/2; j++)
  379.                 *s++ = (
  380.                            ( ct1[tdist5[LONGY+i-g1.y][LONGX+j-g1.x]]
  381.                            +ct2[tdist5[LONGY+i-g2.y][LONGX+j-g2.x]]
  382.                            -ct3[tdist5[LONGY+i-g3.y][LONGX+j-g3.x]]
  383.                            ) /1);
  384.         }
  385.         VGA_VSync();
  386.         time++;
  387.         DumpScr();
  388.  
  389.         MoveCenter(&g1);
  390.         MoveCenter(&g2);
  391.         MoveCenter(&g3);
  392.  
  393.     }
  394. //    getch();
  395.  
  396.  
  397.     time = 0;
  398.     PAL_SetPal(pal2+(3*128)*CambPal);
  399.     CambPal = (CambPal)? 0:1;
  400.  
  401.     while (time < 20*10 && !kbhit()) {
  402.  
  403.         ct1 = CosTab + (fase1 += wt1) % 1024;
  404.         ct2 = CosTab + (fase2 += wt2) % 1024;
  405.         ct3 = CosTab + (fase3 += wt3) % 1024;
  406.  
  407.  
  408.         for (i = LONGY/2; i < LONGY+LONGY/2; i++) {
  409.             s = scr[i-LONGY/2];
  410.             for (j = LONGX/2; j < LONGX+LONGX/2; j++)
  411.                 *s++ =
  412.                            ( ct1[tdist1[LONGY+i-g1.y][LONGX+j-g1.x]]
  413.                            +ct2[tdist2[LONGY+i-g2.y][LONGX+j-g2.x]]
  414.                            +ct3[tdist3[LONGY+i-g3.y][LONGX+j-g3.x]]
  415.                            ) /4;
  416.         }
  417.         VGA_VSync();
  418.         time++;
  419.         DumpScr();
  420.  
  421.         MoveCenter(&g1);
  422.         MoveCenter(&g2);
  423.         MoveCenter(&g3);
  424.  
  425.     }
  426.  
  427.     if (!kbhit())
  428.         goto otra;
  429.  
  430.     getch();
  431.  
  432.     regs.w.ax = 0x3;
  433.     int386(0x10, ®s, ®s);
  434.  
  435.     puts(
  436. "Intro coded during the Posadas Amiga Party in 1995.\n"
  437. "   Original idea by OLS/Iguana.\n"
  438. "   Additional code by Jare/Iguana and Zhorlack/W.A.H.T.\n"
  439. "   PMODE/W 1.16 by Tran & Daredevil.\n"
  440. "\n"
  441. "Only tools available were Watcom C 10.0a, QEdit, Boxer and Animator 1.0.\n"
  442. "Only machine available was a !portable! Dell 486-75.\n"
  443. "\n"
  444. "Greetings to all PC dudes, and also to all Amiga dudes that own a PC and\n"
  445. "don't dare confess it. :)\n"
  446. "Also to all participants in the party, the organizers, the three babes\n"
  447. "dressed in black last night, and the swimming pool watchman.\n"
  448. "\n"
  449. "See you soon at the Euskal Party! (12-15 October, 1995, Tolosa, Spain).\n"
  450. "For more info get the Invitation: EUINVTRO.ZIP at the usual sites.\n"
  451. "\n"
  452. "That's all, folks!\n"
  453. );
  454. }
  455.